package action.user;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;

import service.QueryService;
import service.UserService;
import bean.User;

import com.opensymphony.xwork2.ActionSupport;

public class UserLoginAction extends ActionSupport {
	private User user;
	private UserService userService;
	private QueryService queryService;
	private List recentUsers;
	private List recentArticles;
	private List recentAlbums;
	
	
	@Override
	public String execute() throws Exception {
		User u=userService.login(user);
		if(u!=null){
			recentUsers=queryService.queryRecentUsers();
			recentArticles=queryService.queryRecentArticles();
			recentAlbums=queryService.queryRecentAlbums();
			user=u;
			Map session=ServletActionContext.getContext().getSession();
			session.put("user", user);
			return SUCCESS;
		}
		return INPUT;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	public QueryService getQueryService() {
		return queryService;
	}

	public void setQueryService(QueryService queryService) {
		this.queryService = queryService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public List getRecentUsers() {
		return recentUsers;
	}

	public void setRecentUsers(List recentUsers) {
		this.recentUsers = recentUsers;
	}

	public List getRecentArticles() {
		return recentArticles;
	}

	public void setRecentArticles(List recentArticles) {
		this.recentArticles = recentArticles;
	}

	public List getRecentAlbums() {
		return recentAlbums;
	}

	public void setRecentAlbums(List recentAlbums) {
		this.recentAlbums = recentAlbums;
	}
	
	
}
